<?
include_once('conn.php');
include_once('include/func.php');
include("user_check.php") ;
$db->DELETE("DELETE FROM `".tablepre."session` WHERE  type = '2' and `uid`='".$checkmember[0][2]."'");
		function item_del($item,$user){
			global $db; global $tablepre;
			//SELECT * FROM `we_session` WHERE `uid` = '5' AND `type` = '1'
			$check_exist = $db->select("SELECT v FROM `".$tablepre."session` WHERE `uid` = '".$user."' AND `type` = '1'");

				$exist_explode=explode(',',substr($check_exist[0][0],1)); //拆分数组
				foreach ($exist_explode as $value){
					if($value<>$item){$v .= ','.$value;}
				}
				$db->UPDATE("UPDATE `".tablepre."session` SET `v`='$v' WHERE `uid`='".$user."'  and type = '1'");  //更新数组
				$db->DELETE("DELETE FROM `".tablepre."session` WHERE `v3`='".$item."' and type = '2' and `uid`='".$user."'");
				//return $v;
			}

if(isset($_GET[delete])){
	//
	item_del($_GET[delete],$checkmember[0][2]);
				header("Location: $nowpage?action=1");
				exit;	
	}

function js_loop($sid){
	global $db; global $tablepre;
	$arr_list = $db->select("SELECT iid FROM `".tablepre."stock_item` where sid = '".$sid."' and `quantity` >= '1' and sale = '1' ");
		for($i=0;$i<count($arr_list);$i++) {
			$v .= 'Number(document.getElementById("count'.$arr_list[$i][0].'").value),';
			}
			return substr($v,0,-1);
	}

?>	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>order view</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>

<style type="text/css">
body,td,th {
	font-size: 12px;
}
#clear{
	clear:both; height:0px; overflow:hidden;}
</style>


<? if(isset($_GET[iframe])){
	?>

<iframe id="iFrame1" name="iFrame1" width="100%" onload="this.height=iFrame1.document.body.scrollHeight" frameborder="0" scrolling="no" src="user_cart.php?action=1"></iframe>

	
	<?
	}?>
<? if($_GET[action]==1){ ?>
<style>.item input{ margin:0px; padding:0px;}</style>
<style>
.cart ul{ margin:0px; padding:0px;}
.cart li{
	margin:0; padding:0 0 0 5px; list-style-type:none; border-bottom:#CCC dotted 1px; border-left:#666 2px solid; border-right:#666 2px solid;}
.cart ol{
	margin:0; padding:0 0 0 5px; list-style-type:none; border-bottom:#666 solid 2px; border-left:#666 2px solid; border-right:#666 2px solid;}
.only{ border:#FFF solid 0px;}
.cart label{ display:block; float:left; padding-top:5px;}
.sp{ border:#FFF 0px solid; border-bottom:#666 1px solid;}
.item_row td{ border-bottom:#CCC dotted 1px;}
</style><div id="show_ch" style="float:right;"></div><div id="loading" style="float:right;">&nbsp;</div><img src="images/ttfjpg.php?t=<? echo CART_REVIEW; ?>&amp;bg=titlebg2.jpg&amp;z=18&amp;x=5&amp;y=22&amp;r=0&amp;b=0&amp;g=0"  />
<table width="840" border="0" cellspacing="0" cellpadding="0" ><script>
function round2(number,fractionDigits){  
    with(Math){  
        return round(number*pow(10,fractionDigits))/pow(10,fractionDigits);  
    }  
}  
//////
</script>
<script src="js/jquery_ajax_item_control.js"></script>
  <?
	
	
	function check_item_is_null($con){
		global $db; global $tablepre;
		$arr_list = $db->select("SELECT value1,aid FROM `".tablepre."stock_attachment` where sid = '".$con."' and type = 'cnsnq' ");
		$t = explode("|", $arr_list[0][0]); 
		array_pop($t);
		foreach ($t as $key => $value) {
		$t2 = explode(",", $value);
		$t3=explode("~",$t2[1]);
		array_pop($t3);
		foreach ($t3 as $key2 => $value2) {
			//$v=?$value2:'';
			if($key2%2==1){
				$v=$value2;
					if($v>0){
					$v2 .=	$key2%2==0?$value2:'';
					$v2.=$value2;
						}
				}
			
			}
		$v2 .='<br />';
		}
		return $v2;
		}
	
	$cart_session = $db->select("SELECT v FROM `".tablepre."session` where `uid` = '".$checkmember[0][2]."' and type = '1'");
	$cart_session[0][0]==null?exit('<br /><br /><br /><br />'.CART_NOTE_EMPTY):'';
	$in_cart_array = substr($cart_session[0][0],1);
	$array_stock = $db->select("SELECT sid,name FROM `".tablepre."stock` where `sid` in (".$in_cart_array.")");
	for($i=0;$i<count($array_stock);$i++){
		?><tr>
    <td  valign="top" >
	<div style="padding:5px 0 5px 0; font-size:14px; font-weight:bold;"><? echo PRODUCT_NAME.'：'.$array_stock[$i][1]; ?> | <a href="?delete=<? echo $array_stock[$i][0];?>" onClick="return confirm('<? echo CART_ARE_YOU_SURE;?>')" ><? echo CART_DELETE;?></a> &nbsp; <? echo PRODUCT_MINIMUN_ORDER.minimun($array_stock[$i][0]).' '.parameters(24)?></div></td>
    </tr><tr>
    <td  valign="top">
    <div class="cart">
    
    <table width="840" border="0" cellspacing="1" cellpadding="1">
  <tr style="background:#CCC;">
 	 <td><? echo PRODUCT_BATCH_NO; ?></td>
    <td><? echo PRODUCT_MODEL; ?></td>
    <td><? echo PRODUCT_COLOR; ?></td>
    <td><? echo PRODUCT_SIZE; ?></td>
    <td><? echo PRODUCT_MATERIAL; ?></td>
    <td><? echo PRODUCT_PRICE; ?></td>
    <td><? echo PRODUCT_CURRENT_STOCK; ?></td>
    <td><? echo PRODUCT_QUANTITY; ?></td>
    <td><? echo CART_TOTAL; ?></td>
    <td><? echo CART_SUB_TOTAL; ?></td>
    
  </tr>
  <?
    $arr_list = $db->select("SELECT name,quality1,quality2,quality3,quantity,price,model,unit,iid,batch FROM `".tablepre."stock_item` where sid = '".$array_stock[$i][0]."' and `quantity` >= '1' and sale = '1' ");
		for($j=0;$j<count($arr_list);$j++) { ?>
        <script>
	
        function showLen<? echo $arr_list[$j][8]; ?>(obj)
{
	var qty<? echo $arr_list[$j][8]; ?>;
	if(document.getElementById("item<? echo $arr_list[$j][8]; ?>").value >= <? echo stock_limit($arr_list[$j][4]);?>){
		qty<? echo $arr_list[$j][8]; ?>=<? echo stock_limit($arr_list[$j][4]);?>;
		}else if(document.getElementById("item<? echo $arr_list[$j][8]; ?>").value >= <? echo parameters(13);?>){
			qty<? echo $arr_list[$j][8]; ?>=<? echo parameters(13);?>;
			}else{
				qty<? echo $arr_list[$j][8]; ?>=document.getElementById("item<? echo $arr_list[$j][8]; ?>").value;
				}
				document.getElementById("item<? echo $arr_list[$j][8]; ?>").value=qty<? echo $arr_list[$j][8]; ?>;
				
	var price<? echo $arr_list[$j][8]; ?>=document.getElementById("price<? echo $arr_list[$j][8]; ?>").value;
	document.getElementById("count<? echo $arr_list[$j][8]; ?>").value=round2(qty<? echo $arr_list[$j][8]; ?>*price<? echo $arr_list[$j][8]; ?>,<? echo parameters(9);?>);
	}
        </script><tr class="item_row">
        <input name="id<? echo $arr_list[$j][8]; ?>" id="jq_item<? echo $arr_list[$j][8]; ?>" value="<? echo $arr_list[$j][8]; ?>" type="hidden" />
        	<input id="jq_limit_item<? echo $arr_list[$j][8]; ?>" value="<? echo stock_limit($arr_list[$j][4]);?>" type="hidden" />
            <input id="jq_sid_item<? echo $arr_list[$j][8]; ?>" value="<? echo $array_stock[$i][0];?>" type="hidden" />
        
        <input name="price<? echo $arr_list[$j][8]; ?>" id="price<? echo $arr_list[$j][8]; ?>" value="<? echo price_descount($checkmember[0][2],$arr_list[$j][5]); ?>" type="hidden" />
        <td><label style="width:80px"><? echo $arr_list[$j][9]; ?></label></td>
     <td><label style="width:80px"><? echo $arr_list[$j][6]==null?attachment(1,$array_stock[$i][0],model):$arr_list[$j][6]; ?></label></td>
     <td><label style="width:80px"><? echo $arr_list[$j][1]; ?></label></td>
     <td><label style="width:80px"><? echo $arr_list[$j][2]; ?></label></td>
     <td><label style="width:80px"><? echo $arr_list[$j][3]; ?></label></td>
     <td><label style="width:155px"><del><? echo unit(mround($arr_list[$j][5])); ?></del> <? echo '(↓'.vip($checkmember[0][2],2).'%)  '.unit(price_descount($checkmember[0][2],$arr_list[$j][5]));?></label></td>
     <td><label style="width:130px;"><? echo stock_limit($arr_list[$j][4])>=parameters(13)?CONFIG_AMOUNT_LIMIT.' '.parameters(13):stock_limit($arr_list[$j][4]); echo ' '.$arr_list[$j][7]; ?></label></td>
     <td><div class="item">
        <input name="item<? echo $arr_list[$j][8] ;?>" id="item<? echo $arr_list[$j][8] ;?>"  value="" size="3" onKeyUp="value=value.replace(/[^\d]/g,''),showLen<? echo $arr_list[$j][8]; ?>(this),sub_total<? echo $array_stock[$i][0];?>(),total()" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" onChange="if(value><? echo stock_limit($arr_list[$j][4]);?>){value='<? echo stock_limit($arr_list[$j][4]);?>';}" onKeyDown="showLen<? echo $arr_list[$j][8]; ?>(this),sub_total<? echo $array_stock[$i][0];?>(this),total()" /></div></td>
        
     <td><input name="count<? echo $arr_list[$j][8]; ?>" id="count<? echo $arr_list[$j][8]; ?>" readonly="readonly" size="4" class="sp" value="" /></td>
     <td>&nbsp;</td></tr>
	<?
	 }
	 ?>
  
    <tr style="background: #F2F2F2;">
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td><? // echo substr(js_loop($array_stock[$i][0]),7,-1); ?>
    <script>
	function sum<? echo $array_stock[$i][0];?>(){
		<?  if(count($arr_list)>1){?>
			var total_arr<? echo $array_stock[$i][0];?> = new Array(<? echo js_loop($array_stock[$i][0]); ?>);
			var total<? echo $array_stock[$i][0];?>=0;
				for(var i<? echo $array_stock[$i][0];?>=0;i<? echo $array_stock[$i][0];?><total_arr<? echo $array_stock[$i][0];?>.length;i<? echo $array_stock[$i][0];?>++){
  				total<? echo $array_stock[$i][0];?> += total_arr<? echo $array_stock[$i][0];?>[i<? echo $array_stock[$i][0];?>];
  					}
					return total<? echo $array_stock[$i][0];?>;
					<? }else{ ?>
					
					return <? echo substr(js_loop($array_stock[$i][0]),7,-1); ?>;
					<? }?>
		}

	function sub_total<? echo $array_stock[$i][0];?>(){
			document.getElementById("sub_total<? echo $array_stock[$i][0];?>").value=round2(sum<? echo $array_stock[$i][0];?>(),<? echo parameters(9);?>);
		}
    </script>
    <input type="text" id="sub_total<? echo $array_stock[$i][0];?>" name="sub_total<? echo $array_stock[$i][0];?>"  size="5" readonly="readonly" class="sp" />
     <? $v .= 'Number(document.getElementById("sub_total'.$array_stock[$i][0].'").value),'; ?></td>
    
  </tr>
</table>
</div>
    </td>
    </tr>
		<?
		}
	?>
</table><table width="100%" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td><script>
function total(){
	<? if(count($array_stock)>1){?>
	var v = new Array(<? echo substr($v,0,-1);?>);
	var total = 0;
	for(var i=0;i<v.length;i++){
		total += v[i];
		}
		
	document.getElementById("total").value=round2(total,<? echo parameters(9);?>);
	<? }else{?>
	document.getElementById("total").value=<? echo substr($v,0,-1);?>;
	<? }?>
	}
</script>



<table width="840" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td width="363"><input type="submit" name="button" value="<? echo CART_SUB_CHECKOUT;?>" style="background:url(images/Mono_085.png) no-repeat; border:0px solid; padding:8px 8px 8px 30px; margin:0 200px 0 0" onClick="if(confirm('<? echo CART_ORDER_CONTINUE;?>')) location='include/create_order.php'"  />
</td>
    <td width="363" align="right"><font size="+1"><? echo CART_ORDER_TOTAL;?></font><? echo $unit[0][0];?></td>
    <td width="98"><? if(parameters(11)==0){?>
<font size="+1"></font><input id="total" name="total" type="text" style="font-size:16px; font-weight:bold; margin:8px; padding:8px; border:#666 2px solid;" size="5" readonly="readonly" value="<? echo read_order_item(3,$arr_list[$j][8],$checkmember[0][2]);?>" />
<? }elseif(parameters(11)==1){?>
<input id="total" name="total" type="text" style="font-size:16px; font-weight:bold; margin:8px; padding:8px; border:#666 2px solid;" size="5" readonly="readonly" value="<? echo read_order_item(3,$arr_list[$j][8],$checkmember[0][2]);?>" /><font size="+1"><? echo $unit[0][0];?></font>
<? } ?></td>
  </tr>
</table>
</td>
  </tr>
</table>

<? } ?>
